package cn.pzh.cloud.service.imp;

import cn.pzh.cloud.client.UserClient;
import cn.pzh.cloud.mapper.OrderMapper;
import cn.pzh.cloud.pojo.TbOrder;
import cn.pzh.cloud.pojo.User;
import cn.pzh.cloud.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImp implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
  /*  @Autowired
    private RestTemplate restTemplate;*/
    @Autowired
    private UserClient userClient;
    @Override
    public TbOrder queryById(Integer orderId) {

        TbOrder order = orderMapper.selectById(orderId);
 /*       //远程调用user
        String url="http://userservice/user/"+order.getUserId();
        User user = restTemplate.getForObject(url, User.class);*/

        //feign实现远程调用
        User user = userClient.queryById(order.getUserId());
        //给order订单设置user对象
        order.setUser(user);
        return order;
    }
}
